import 'dart:convert';
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:sp_util/sp_util.dart';
import 'package:yp/config/config.dart';
import 'package:yp/services/api.dart';
import 'collage_view.dart';
import 'collage_state.dart';

class CollageLogic extends GetxController {
  final CollageState state = CollageState();
  final CollagePage views = CollagePage();
  @override
  void onReady() {
    // getMembershipInterests();
    // TODO: implement onReady
    super.onReady();
  }



//获取今日必拼数据
  getqueryspellgroup() {
    print(Get.arguments);
    var params = {'cat_id':null,"data_sign": 0, "channel_num_id": 99, "use_platform": 3, "shop_id":state.collageShopId, "cat1_id": state.groupClassifyId, "buy_type": 1, "page_num": 1, "page_size": 999};

    Api.queryspellgroup(params).listen((event) {
              print('今日必拼');
    print(event);
      if (event['code'] == 0) {
        state.todayData.clear();
        if (event['buy_id_list'] != null && event['buy_id_list'].length > 0) {
          if(state.activityNumId==null) {
            state.todayData = event['buy_id_list'];
          }else {
            event['buy_id_list'].forEach((element) {
              if (element['ecactivity_id'] == state.activityNumId) {
                state.todayData.add(element);
              }
            });
          }
        }
      }
      update();
    });
  }

  //获取热拼榜数据
  gethotproduct() {
    var params = {'cat_id':null,"data_sign": 0, "channel_num_id": 99, "use_platform": 3, "shop_id": state.collageShopId, "buy_type": 2, "cat1_id": state.groupClassifyId};
    Api.queryhotproduct(params).listen((event) {
      if (event['code'] == 0) {
        if (event['buy_id_list'] != null && event['buy_id_list'].length > 0) {
          if(state.activityNumId==null) {
            state.hotData = event['buy_id_list'];
          }else{
            event['buy_id_list'].forEach((element) {
              if (element['ecactivity_id'] == state.activityNumId) {
                state.hotData.add(element);
              }
            });
          }
        }else{
            state.hotData=[];
        }
      }

      update();
    });
  }
}
